package com.spring.gop.proj.service;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.spring.gop.proj.interfaces.TicketDao;
import com.spring.gop.proj.interfaces.TicketService;
import com.spring.gop.proj.model.MyPoint;
import com.spring.gop.proj.model.User;

@Service
public class TicketServiceImpl implements TicketService {

	@Autowired TicketDao ticketDao;
	
	@Transactional
	public void insertTicket(MyPoint myPoint, User user) {
		String note = "포인트";
		String title = "포인트 충전";
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Calendar cal = Calendar.getInstance();
		myPoint.setPoint_note(note);
		myPoint.setPoint_title(title);
		myPoint.setPoint_chargedate(sdf.format(cal.getTime()));
		
		ticketDao.insertTicket(myPoint);
		
		user.setMember_point(myPoint.getPoint_value() + user.getMember_point());
		ticketDao.updateTicket(user);
	}
	
	public List<MyPoint> selectAllMyPoint() {
		return ticketDao.selectAllMyPoint();
	}
}
